import {
  HYEventStore
} from "hy-event-store";

import {
  APIMusic
} from "../service/api_music"

const rankingMap = {
  3778678: "hotRanking",
  19723756: "upRanking",
  3779629: "newRanking",
  2884035: 'originRanking',
  5453912201: "blackVipRanking"
}

const rankingStore = new HYEventStore({
  state: {
    hotRanking: {},
    upRanking: {},
    newRanking: {},
    originRanking: {},
    blackVipRanking: {}
  },
  actions: {
    getRankingDataAction(ctx) {
      // 热歌榜 3778678
      // 飙升榜 19723756
      // 新歌榜 3779629
      // 原创榜 2884035
      // 黑胶VIP爱听榜 5453912201

      Object.keys(rankingMap).forEach(key => {
        APIMusic.getRankings(parseInt(key)).then(res => {
          ctx[rankingMap[parseInt(key)]] = res.playlist
        }).catch(err => {
          console.error(err);
        })
      })
    }
  }
})

export {
  rankingStore,
  rankingMap
}